<template>
  <div class="editor-container">
    <el-form ref="form" :model="form" :rules="rules">
      <el-form-item label="" prop="content" class="vab-quill-content">
        <vab-quill
          v-model="form.goods_introduce"
          :min-height="300"
          :options="options"
        ></vab-quill>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleAddShop">添加商品</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
  import vabQuill from '@/plugins/vabQuill'
  export default {
    name: 'GoodsContent',
    components: { vabQuill },
    data() {
      return {
        options: {
          theme: 'snow',
          bounds: document.body,
          debug: 'warn',
          modules: {
            toolbar: [
              ['bold', 'italic', 'underline', 'strike'],
              [{ header: [1, 2, 3, 4, 5, 6, false] }],
              [{ size: ['small', false, 'large', 'huge'] }],
              [{ color: [] }, { background: [] }],
              ['blockquote', 'code-block'],
              [{ list: 'ordered' }, { list: 'bullet' }],
              [{ script: 'sub' }, { script: 'super' }],
              [{ indent: '-1' }, { indent: '+1' }],
              [{ align: [] }],
              [{ direction: 'rtl' }],
              [{ font: [] }],
              ['clean'],
              ['link', 'image'],
            ],
          },
          placeholder: 'Insert text here...',
          readOnly: false,
        },
        borderColor: '#dcdfe6',
        dialogTableVisible: false,
        form: {
          goods_introduce: '',
        },
        rules: {
          content: [
            {
              required: true,
              message: '请输入内容',
              trigger: 'blur',
            },
          ],
        },
      }
    },
    methods: {
      handleAddShop() {
         //设置属性
          let attrs={attrs:this.$store.getters['goods/get_attr_valsAnd_id']};
          this.$store.commit('goods/CHANGE_ADDGOODSQUERY',attrs);
          //设置参数
         /*  let data=this.$store.state.goods.addGoodsQuery; */
          this.$store.dispatch('goods/Acs_postAddGoods').then(res=>{
            //console.log(res);
            this.$router.push('/goods');
            this.$store.dispatch('goods/Acs_getGoods')
          }).catch(err=>console.log(res))
      },
    },
    watch:{
        /* 'this.form.goods_introduce':{
            handler:function(newVal,oldVal){
                console.log(newVal);
                this.$store.commit('goods/CHANGE_ADDGOODSQUERY',newVal)
            },
            deep:true,
            immediate:true
        } */
    },
    beforeUpdate() {
        this.$store.commit('goods/CHANGE_ADDGOODSQUERY',this.form)
    },
  }
</script>
<style lang="scss" scoped>
  .editor-container {
    .news {
      &-title {
        text-align: center;
      }
      &-content {
        ::v-deep {
          p {
            line-height: 30px;
            img {
              display: block;
              margin-right: auto;
              margin-left: auto;
            }
          }
        }
      }
    }
    .vab-quill-content {
      ::v-deep {
        .el-form-item__content {
          line-height: normal;
        }
      }
    }
  }
</style>